package week9;

import javax.swing.*;
import java.awt.*;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;

/**
 * @author The setting sun
 * @version 1.0
 * @title: Work4
 * @description: TODO
 * @date 2021/11/4 15:15
 */
public class Work4 {
    public static void main(String[] args) {
        new MyFrame2().init();
    }
}

class MyFrame2 {
    JFrame frame = new JFrame();
    MyPaint mp = new MyPaint();

    public void init() {
        mp.addMouseListener(new MouseAdapter() {
            @Override
            public void mouseClicked(MouseEvent e) {
                new Meteor(e.getX(), e.getY(), mp.getGraphics()).start();
            }
        });

        frame.add(mp);
        frame.setVisible(true);
        frame.setSize(1920, 1080);
        frame.setLocationRelativeTo(null);
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    }

    class Meteor extends Thread{
        int x;
        int y;
        Graphics g;

        public Meteor(int x, int y, Graphics g) {
            this.x = x;
            this.y = y;
            this.g = g;
        }

        @Override
        public void run() {
            int paceX = 5;
            int paceY = 2;
            int i = 0;
            int size = 1;
            g.setColor(Color.WHITE);
            g.fillOval(x, y, 17, 17);

            while (true) {
                try {
                    Thread.sleep(100);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }

                g.fillOval(x + paceX * i, y - paceY * i, 17 - size, 17 - size);

                i++;
            }
        }
    }
}

class MyPaint extends JPanel{
    @Override
    public void paint(Graphics g) {
        Image img = new ImageIcon("Dusk.jpg").getImage();

        g.drawImage(img, 0, 0, null);
    }
}




